<div id="share-container" class="container">
    <div id="msg-container">
        <h2 class="error-tips"></h2>
    </div>
    <form action="{:U('Question/share')}" method="POST">
        <input id="qid" type="hidden" name="qid" value="{$question.question_id}" />
        <table class="tb" cellspacing="5" cellpadding="5">
            <tr>
                <td align="right">{$Think.lang.question}:</td>
                <td><a href="{$question.question_id|format_question_url=$question['title']}">{$question.title}</a></td>
            </tr>
            <tr>
                <td align="right" valign="top"><label for="recipient">{$Think.lang.email_to}:</label></td>
                <td><input id="recipient" class="input" type="text" name="recipient" maxlength="120" size="70" style="margin-bottom:5px;" /><br/>{$Think.lang.email_to_explain}</td>
            </tr>
            <tr>
                <td align="right" valign="top"><label for="message">{$Think.lang.email_message}:</label></td>
                <td><textarea id="message" class="textarea" name="message" rows="5" cols="80">{$Think.lang.email_message_default}</textarea><div id="message-counter" class="counter"></div></td>
            </tr>
            <tr>
                <td align="right"></td>
                <td><input id="cc" type="checkbox" name="cc" value="1">&nbsp;<label for="cc">{$Think.lang.email_cc_me}</label></td>
            </tr>
            <eq name="captcha" value="1">
            <tr>
                <td align="right"><label for="verify">{$Think.lang.captcha}:</label></td>
                <td><div class="captcha-container"><input id="verify" class="input" type="text" name="verify" size="20" />&nbsp;<img class="captcha" src="{:U('Ajax/captcha')}" title="{$Think.lang.captcha_again}" onclick="reCaptcha(this);" /></div></td>
            </tr>
            </eq>
            <tr>
                <td align="right"></td>
                <td><input id="share-submit" class="button" type="button" value="{$Think.lang.send_email}" /><span id="waiting">{$Think.lang.email_sending}</span></td>
            </tr>
        </table>
    </form>
</div>


<load href="__PUBLIC__/Js/jquery.artTxtCount.js" />
<script type="text/javascript">
$(function(){
    $('#message').artTxtCount($('#message-counter'), 1500);
    $('#share-submit').click(function(){
        var url = "{:U('Question/share')}";
        var data = {
            qid: $('#qid').val(),
            recipient: $('#recipient').val(),
            message: $('#message').val(),
            cc: $('#cc').attr('checked') ? 1 : 0,
            verify: $('#verify').val()
        };
        $('#waiting').show();
        $.post(url, data, function(json){
            $('#waiting').hide();
            $('#msg-container').show();
            var json = eval('('+json+')');
            if(json.status == 0){
                $('#msg-container>h2').html(json.info);
                return false;
            }else{
                $('#msg-container>h2').attr('class','success-tips').html(json.info);
                $('#share-submit').attr({disabled:true, class:'alt-button'});
                setTimeout(function(){
                    $.dialog.get(data.qid).close();
                }, WAIT_TIME);
            }
        });
        return false;
    });
});
</script>
